/**
 * Flogger - Logging Console for ActionScript
 * Copyright (c) 2010 Ariel Flesler | aflesler(at)gmail(dot)com
 * Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php)
 * Date: 12/29/2010
 *
 * @author Ariel Flesler
 * @version 1.0.0
 */

package
{
	import com.flesler.flogger.Flogger;
	
	import flash.display.Sprite;
	import flash.events.KeyboardEvent;
	import flash.text.TextField;
	
	[SWF(width='800', height='200', backgroundColor='0x000000', frameRate='25')]
	
	// TODO: Create a simple GUI instead of key bindings
	
	public class FloggerTest extends Sprite
	{
		private var flogger:Flogger;
		
		public function FloggerTest()
		{
			init();
		}
		
		private function init():void
		{
			flogger = new Flogger();
			
			var field:TextField = new TextField();
			field.text = 'Use QWERT keys to test log levels';
			field.textColor = 0xFFFFFF;
			field.width = stage.stageWidth;
			field.mouseEnabled = false;
			addChild(field);
			
			flogger.receiveCommands(commandReceived);
			
			stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeys);
		}
		
		private function commandReceived(msg:String):void
		{
			flogger.debug('Received '+msg);
		}
		
		private function checkKeys(e:KeyboardEvent):void
		{
			switch (String.fromCharCode(e.charCode))
			{
				case 'q': flogger.debug('This is a debug message'); break;
				case 'w': flogger.info('This is an info message'); break;
				case 'e': flogger.warn('This is a warning message'); break;
				case 'r': flogger.error('This is an error message'); break;
				case 't': flogger.fatal('This is a fatal message'); break;
			}
		}
	}
}